import { 
  ADD,
  ADD_SUCCESS,
  ADD_FAIL,
  SET_SIGN,
  SET_INDUSTRY, 
  SET_SCENARIOS, 
  SET_DATA,
  GET_INDUSTRY_ENUM_SUCCESS,
  GET_SCENARIOS_ENUM_SUCCESS
} from '@/actions/signEdit'

const initState = {
  industry: '',
  scenarios: '',
  sign: '',
  addButtonLoading: false,
  industryEnum: [], 
  scenariosEnum: []
}

export default function signEditReducer(state = initState, action) {
  switch (action.type) {
    case ADD:
      return { ...state, addButtonLoading: true }
      break;

    case ADD_SUCCESS:
      return { ...state, addButtonLoading: false, industry: '', scenarios: '', sign: '' }
      break;

    case ADD_FAIL:
      return { ...state, addButtonLoading: false }
      break;

    case SET_SIGN:
      return { ...state, sign: action.sign }
      break;

    case SET_INDUSTRY:
      return { ...state, industry: action.industry }
      break;
    
    case SET_SCENARIOS:
      return { ...state, scenarios: action.scenarios }
      break;

    case SET_DATA:
      const { sign, industry, application: scenarios, id } = action.data
      return { ...state, sign, industry, scenarios, id }
      break;

    case GET_INDUSTRY_ENUM_SUCCESS:
      return { ...state, industryEnum: action.industryEnum }
      break;

    case GET_SCENARIOS_ENUM_SUCCESS:
      return { ...state, scenariosEnum: action.scenariosEnum }
      break;

    default:
      return state
      break;
  }
}